package com.huwei.modules.base.properties;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import lombok.Data;

@Data
@Component
@ConfigurationProperties()
@PropertySource(value = { "classpath:config/properties/pro-shiro.properties" }, encoding = "utf8")
public class ShiroProperties {
	
	private String urlFilterSplitSymbol;
	private String urlFilterRoleOr;
	private String loginUrl;
	private String successUrl;
	private ArrayList<String> urlFilterList = new ArrayList<String>();
	
	public LinkedHashMap<String, String> urlFilter(){
		LinkedHashMap<String, String> res = new LinkedHashMap<String, String>();
		for(int i = 0 ,len = this.urlFilterList.size() ;i < len ;++i) {
			String temp = this.urlFilterList.get(i);
			String[] mapping = null;
			if(temp == null || (mapping = temp.split(this.urlFilterSplitSymbol)).length != 2) {
				throw new RuntimeException("加载shiro配置文件路径拦截信息失败，原因：配置数据不符合规范：urlFilterSplitSymbol="
						+ this.urlFilterSplitSymbol + " ;urlFilterList[" + i + "]=" + temp);
			}
			res.put(mapping[0], mapping[1]);
		}
		return res;
	}
}
